package cn.fxyz.web.controller;
import java.util.List;

import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.fxyz.entity.Dinnertable;
import cn.fxyz.page.PageBean;
import cn.fxyz.service.DinnertableService;

@Controller
@RequestMapping("/dinnertable")
public class DinnertableController {
	@Resource
	private DinnertableService dinnertableService;
	
	//查询所有餐桌+条件查询+分页查询
	private int pageSize = 10;  //固定值
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	@RequestMapping("findAll")
	public String findAll(PageBean<Dinnertable> pagebean,Dinnertable dinnertable,Model model) {
		PageBean<Dinnertable> pageBean = dinnertableService.findAll(dinnertable, pagebean.getPageNum(), pageSize);
		model.addAttribute("pageBean", pageBean);
		return "backstage/detail/boardList";
	}
	
	//ajax查询所有餐桌
	@RequestMapping("ajaxFindAll")
	@ResponseBody
	public List<Dinnertable> ajaxfindAll() {
		List<Dinnertable> findAll = dinnertableService.findAll();
		System.out.println(findAll);
		return findAll;
	}
	
	//添加餐桌
	@RequestMapping("add" )
	public String add(Dinnertable dinnertable) {
		dinnertableService.add(dinnertable);
		return "redirect:findAll.do";
		
	}
	//删除餐桌
	@RequestMapping("remove")
	public String remove(Dinnertable dinnertable) {
		System.out.println(dinnertable.getId());
		dinnertableService.remove(dinnertable);
		return "redirect:findAll.do";
	}
	//退桌预定
	@RequestMapping("modify")
	public String update(Dinnertable dinnertable) {
		dinnertableService.modify(dinnertable);
		return "redirect:findAll.do";
	}
	/*//查询所有餐桌+条件查询
	@RequestMapping("findAll")
	public String findAll(Dinnertable dinnertable,Model model) {
		List<Dinnertable> dinnertables = dinnertableService.findAll(dinnertable);
		model.addAttribute("dinnertables", dinnertables);
		return "backstage/detail/boardList";
	}*/
	public DinnertableService getDinnertableService() {
		return dinnertableService;
	}
	public void setDinnertableService(DinnertableService dinnertableService) {
		this.dinnertableService = dinnertableService;
	}
	
	
}
